/*
 * adxl345.h
 *
 *  Created on: Aug 28, 2013
 *      Author: IEUser
 */

#ifndef ADXL345_H_
#define ADXL345_H_

/******************************************************************************************
 *	Deklaracje dołączanych plików nagłówkowych i bibliotek								 *
 *****************************************************************************************/
#include <avr/io.h>

#include "twi.h"

/******************************************************************************************
 *	Makrodefinicje															 			 *
 *****************************************************************************************/
#define ADXL345  0x49

#define DEVID			0x00	/* Device ID */
#define THRESH_TAP		0x1D	/* Tap threshold */
#define OFSX			0x1E	/* X-axis offset */
#define OFSY			0x1F	/* Y-axis offset */
#define OFSZ			0x20	/* Z-axis offset */
#define DUR				0x21	/* Tap duration */
#define LATENT			0x22	/* Tap latency */
#define WINDOW			0x23	/* Tap window */
#define THRESH_ACT		0x24	/* Activity threshold */
#define THRESH_INACT	0x25	/* Inactivity threshold */
#define TIME_INACT		0x26	/* Inactivity time */
#define ACT_INACT_CTL	0x27	/* Axis enable control for activity and inactivity detection */
#define THRESH_FF		0x28	/* Free-fall threshold */
#define TIME_FF			0x29	/* Free-fall time */
#define TAP_AXES		0x2A	/* Axis control for tap/double tap */
#define ACT_TAP_STATUS	0x2B	/* Source of tap/double tap */
#define BW_RATE			0x2C	/* Data rate and power mode control */
#define POWER_CTL		0x2D	/* Power-saving features control */
	#define MEASURE		0x01	/* Measurement mode */
	#define STANDBY		0x01	/* Standby mode */
#define INT_ENABLE		0x2E	/* Interrupt enable control */
#define INT_MAP			0x2F	/* Interrupt mapping control */
#define INT_SOURCE		0x30	/* Source of interrupts */
#define DATA_FORMAT		0x31	/* Data format control */
	#define RANGE_2G	0x00	/* 2g data range */
	#define RANGE_4G	0x01	/* 4g data range */
	#define RANGE_8G	0x02	/* 8g data range */
	#define RANGE_16G	0x03	/* 16g data range */
#define DATAX0			0x32	/* X-Axis Data 0 */
#define DATAX1			0x33	/* X-Axis Data 1 */
#define DATAY0			0x34	/* Y-Axis Data 0 */
#define DATAY1			0x35	/* Y-Axis Data 1 */
#define DATAZ0			0x36	/* Z-Axis Data 0 */
#define DATAZ1			0x37	/* Z-Axis Data 1 */
#define FIFO_CTL		0x38	/* FIFO control */
#define FIFO_STATUS		0x39	/* FIFO status */


/******************************************************************************************
 *	Deklaracje zmiennych pomocniczych i globalnych										 *
 *****************************************************************************************/

/******************************************************************************************
 *	Deklaracje funkcji								 									 *
 *****************************************************************************************/
void adxl345_write_byte(uint8_t address, uint8_t byte);
uint8_t adxl345_read_byte(uint8_t address, uint8_t ack);
void adxl345_config(uint8_t mode, uint8_t range);
void adxl345_get_data(uint16_t *x, uint16_t *y, uint16_t *z);

#endif /* ADXL345_H_ */
